package cn.schoolwow.util.test.module.multipleThread.testcase;

import cn.schoolwow.quickflow.domain.FlowContext;
import cn.schoolwow.quickflow.flow.BusinessFlow;
import cn.schoolwow.util.test.module.query.dictionary.testcase.QueryDictionaryTestCaseFlow;
import cn.schoolwow.util.test.module.query.instanceList.testcase.InstanceQueryGroupByFieldTestCaseFlow;
import cn.schoolwow.util.test.module.query.instanceList.testcase.InstanceQueryTestCaseFlow;
import cn.schoolwow.util.test.module.query.jsonarray.testcase.JSONQueryGroupByFieldTestCaseFlow;
import cn.schoolwow.util.test.module.query.jsonarray.testcase.JSONQueryTestCaseFlow;
import cn.schoolwow.util.test.module.query.queryPackage.service.QueryPackageTestCaseFlow;
import cn.schoolwow.util.test.module.query.reflection.testcase.QueryReflectionTestCaseFlow;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.TimeUnit;

public class MultipleThreadQueryTestCaseFlow implements BusinessFlow {
    @Override
    public void executeBusinessFlow(FlowContext flowContext) throws Exception {
        ExecutorService executorService = Executors.newFixedThreadPool(Runtime.getRuntime().availableProcessors());
        executorService.execute(()->{
            flowContext.startFlow(new InstanceQueryTestCaseFlow())
                    .next(new InstanceQueryGroupByFieldTestCaseFlow())
                    .next(new JSONQueryTestCaseFlow())
                    .next(new JSONQueryGroupByFieldTestCaseFlow())
                    .next(new QueryReflectionTestCaseFlow())
                    .next(new QueryPackageTestCaseFlow())
                    .next(new QueryDictionaryTestCaseFlow())
                    .execute();
        });
        executorService.shutdown();
        executorService.awaitTermination(1, TimeUnit.MINUTES);
    }

    @Override
    public String name() {
        return "多线程执行查询测试用例";
    }
}
